package com.dtguai.web.web.modules.service.impl;

import com.dtguai.web.base.form.BaseFrom;
import com.dtguai.web.base.service.impl.BaseServiceImpl;
import com.dtguai.web.util.redis.RedisUtil;
import com.dtguai.web.web.modules.dao.CourseTrainingUserDao;
import com.dtguai.web.web.modules.model.CourseTrainingUser;
import com.dtguai.web.web.modules.service.CourseTrainingUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户培训班
 *
 * @author  guo
 * @date 2019-01-28 11:44:36
 */
@Service("courseTrainingUserService")
public class CourseTrainingUserServiceImpl extends BaseServiceImpl<CourseTrainingUser> implements CourseTrainingUserService {

    @Autowired
    RedisUtil redisUtil;

    /**
     * 根据条件查询  自定义xml
     */
    @Override
    public List<CourseTrainingUser> findCourseTrainingUserByXml(BaseFrom courseTrainingUser) {
        return ((CourseTrainingUserDao) getMapper()).selectByCourseTrainingUserModel(courseTrainingUser);
    }

    /**
     * Select标签 根据主键查询对象
     */
    @Override
    public CourseTrainingUser findCourseTrainingUserById(Integer id) {
        return ((CourseTrainingUserDao) getMapper()).findCourseTrainingUserById(id);
    }

    /**
     * 根据id从cache读取数据
     */
    @Override
    public CourseTrainingUser getCourseTrainingUserCacheById(Integer id) {
        if (null == id) {
            return null;
        }
        CourseTrainingUser courseTrainingUser = (CourseTrainingUser) redisUtil.getModel(new CourseTrainingUser(id));
        if (null == courseTrainingUser) {
            courseTrainingUser = super.selectByKey(id);
            if (null != courseTrainingUser) {
                redisUtil.setPageModel(courseTrainingUser);
            }
        }
        return courseTrainingUser;
    }
}